GDK W32: Always process all available messages
authorJeremy Tan <jtanx@outlook.com>
Sat, 17 Sep 2016 09:19:59 +0000 (17:19 +0800)
committerРуслан Ижбулатов <lrn1986@gmail.com>
Mon, 19 Sep 2016 12:36:51 +0000 (12:36 +0000)
commita5c8fedf47759d5dbdd92e9b57e830040153f710
treec0b889fa9d9f4c634633f62e630362f1cf3a347a
parent6d722f2aaff3a5a41fc577829749f26112cd9b00
GDK W32: Always process all available messages

The GLib main loop blocks on MsgWaitForMultipleObjectsEx to
determine if there are any incoming messages while also allowing
for background tasks to run. If all available messages are not
processed after MsgWaitForMultipleObjectsEx has signaled that
there are available, CPU usage will skyrocket.

From my limited understanding (by inspection of profiling
under Visual Studio):
Key is pressed - MsgWaitForMultipleObjectsEx unblocks, and
sends message to GDK's event handler. Some event is now queued.

g_poll unblocks, calls the g_event_dispatch which finally
resolves to gdk_event_dispatch. This then calls
_gdk_win32_display_queue_events, but since a message is already
queued, it fails to call PeekMessage and returns immediately.

At the next iteration, g_poll again calls MsgWaitForMultipleObjectsEx
which queues yet another event and returns almost immediately, since
there are events available which haven't been processed by PeekMessage.

The dispatch function is then called and the process repeats.

https://bugzilla.gnome.org/show_bug.cgi?id=771568
gdk/win32/gdkevents-win32.c